from pymysql import *

con = connect(host='localhost', port=3306, database='stock_db', user='root', password='root', charset='utf8')
cur = con.cursor()
sql = """select * from info;"""
cur.execute(sql)
data_from_mysql = cur.fetchall()

for tr_data in data_from_mysql:
    print(tr_data)
    for td_data in tr_data:
        print(td_data)


#
# # 创建连接
# con = connect(host="127.0.0.1", port=3306, database="clouddb01", user="root", password="root", charset="utf8")
# # 创建Cursor对象
# cur = con.cursor()
# # 查询所有数据
# count = cur.execute("select * from dept")
# print("打印dept表中多少条", count)

# 获取该表中所有数据
# list1 = cur.fetchall()
# for temp in data_from_mysql:
#     print(temp)

cur.close()
# 关闭连接
con.close()
# 插入语句
# rows = cur.execute("insert into dept(dname,db_source) values('事务综合部','clouddb01')")
# 修改语句
# rows = cur.execute("update dept set dname='实务综合1部' where deptno=10")
# 删除语句
# rows = cur.execute("delete from dept where deptno=10")
# print("影响的行数", rows)
# # 提交
# con.commit()
# # 关闭游标
# cur.close()
# # 关闭连接
# con.close()


# def main():
#
#
#     conn = connect(host='localhost', port=3306, database='clouddb01', user='root', password='root', charset='utf8')
#     # 获得Cursor对象
#     cursor = conn.cursor()
#     # 插入10万次数据
#     for i in range(100000):
#         cursor.execute("insert into test_index values('ha-%d')" % i)
#     # 提交数据
#     conn.commit()
#
#
# if __name__ == "__main__":
#     main()
